package com.huatai.datadevelop.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.huatai.common.error.exception.ServiceException;
import com.huatai.datadevelop.entity.SysConfigEntity;
import com.huatai.datadevelop.mapper.SysConfigMapper;
import com.huatai.datadevelop.utils.PageUtils;
import com.huatai.datadevelop.utils.Query;
import com.huatai.datadevelop.utils.SysConfigRedis;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfigEntity> {
	@Autowired
	private SysConfigRedis sysConfigRedis;

	public String getValue(String key) {
		SysConfigEntity config = sysConfigRedis.get(key);
		if (config == null) {
			List<SysConfigEntity> param_key = this.list(new QueryWrapper<SysConfigEntity>().eq("param_key", key));
			if(param_key!=null && param_key.size()>0){
				config = param_key.get(0);
			}
			sysConfigRedis.saveOrUpdate(config);
		}
		return config == null ? null : config.getParamValue();
	}

}
